<script setup lang="ts">
import { toPercent } from '@/utils/filter'

withDefaults(
  defineProps<{
    flag: string
    itemValues: {
      title: string
      values: string | number[]
      green?: boolean
      red?: boolean
    }[]
    progressData: {
      targetGap: number
      targetGapRed: boolean
      progress: number | string
      countryValue: number
      areaValue: number
    }
  }>(),
  {
    flag: '',
    itemValues: () => []
  }
)
</script>

<template>
  <div class="order-sales-progress">
    <div class="overview">
      <div class="item-value" v-for="data in itemValues" :key="data.title">
        <div class="title">{{ data.title }}</div>
        <div class="values">
          <div
            v-for="(value, index) in data.values"
            :key="index"
            :class="[`value${index + 1}`, { green: data.green, red: data.red }]"
          >
            {{ `${index > 0 ? '/' : ''}${value}` }}
          </div>
        </div>
      </div>
    </div>
    <div class="progress-container">
      <div class="progress-bg">
        <div
          class="progress"
          :class="{ normal: flag === '进度正常' }"
          :style="{
            width: `${Number(progressData.progress) > 100 ? 100 : progressData.progress}%`
          }"
        >
          {{ `进度：${toPercent(progressData?.progress, 1, false, '%', 1)}` }}
        </div>
        <div class="target-num">
          <div>目标差：</div>
          <div class="num" :class="{ red: progressData?.targetGapRed }">
            {{ progressData?.targetGap }}
          </div>
        </div>
        <div class="progress-point">
          <div
            class="top"
            :style="{
              left: `${
                Number(progressData?.countryValue) > 100 ? 100 : progressData?.countryValue
              }%`
            }"
            :class="{
              zero: !progressData?.countryValue || progressData?.countryValue < 5,
              max: progressData?.countryValue > 95
            }"
          >
            {{ `全国进度：${toPercent(progressData?.countryValue, 1, false, '%', 1)}` }}
          </div>
          <div
            class="arrow-top"
            :class="{
              'arrow-max': progressData?.countryValue > 95
            }"
            :style="{
              left: `${
                Number(progressData?.countryValue) > 100 ? 100 : progressData?.countryValue
              }%`
            }"
          />
        </div>
        <div class="progress-point">
          <div
            class="bottom"
            :style="{
              left: `${Number(progressData?.areaValue) > 100 ? 100 : progressData?.areaValue}%`
            }"
            :class="{
              zero: !progressData?.areaValue || progressData?.areaValue < 5,
              max: progressData?.areaValue > 95
            }"
          >
            {{ `区域进度${toPercent(progressData?.areaValue, 1, false, '%', 1)}` }}
          </div>
          <div
            class="arrow-bottom"
            :class="{
              'arrow-max': progressData?.areaValue > 95
            }"
            :style="{
              left: `${Number(progressData?.areaValue) > 100 ? 100 : progressData?.areaValue}%`
            }"
          />
        </div>
      </div>
    </div>
    <div class="right-top-tag" :class="{ normal: flag === '进度正常' }">{{ flag }}</div>
  </div>
</template>

<style lang="less" scoped>
// @media screen and (width: 1920px) and (max-height: 1080px) {
//   .order-sales-progress {
//     height: calc(100% - 228px);
//   }
// }
.order-sales-progress {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 134px;
  // height: calc(134 * (100vh - (72px + 128px + 8px * 3 + 8px * 2)) / (2 * 372));
  padding: 12px 12px 10px 12px;
  border-radius: 8px;
  border: 1px solid #4c76ec;
  background: linear-gradient(180deg, rgba(0, 31, 109, 0.86) 0%, rgba(10, 30, 84, 0.86) 100%);
  .overview {
    display: flex;
    align-items: center;
    justify-content: space-between;
    .item-value {
      flex: 1;
      display: flex;
      flex-direction: column;
      gap: 4px;
      .title {
        color: var(--unnamed, #fff);
        font-family: Alibaba PuHuiTi 2;
        font-size: 14px;
        font-style: normal;
        font-weight: 400;
        line-height: 14px; /* 100% */
        .gray {
          color: #799bc0;
        }
      }
      .values {
        display: flex;
        align-items: baseline;
        font-family: DIN Alternate;
        font-style: normal;
        font-weight: 700;
        line-height: 24px;
        .value1 {
          color: #fff;
          font-size: 24px;
        }
        .value2 {
          color: rgba(255, 255, 255, 0.8);
          font-size: 14px;
        }
        .green {
          color: #35c08e;
        }
        .red {
          color: #ff5656;
        }
      }
    }
  }
  .progress-container {
    flex: 1;
    display: flex;
    align-items: center;
    .progress-bg {
      width: 100%;
      position: relative;
      height: 20px;
      background: rgba(227, 236, 255, 0.1);
      text-align: right;
      padding: 0px 8px;
      .progress {
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        background: linear-gradient(270deg, #ff8a00 0%, #ff3d00 100%);
        height: 20px;
        padding-left: 8px;
        text-align: left;
        color: var(--unnamed, #fff);
        font-family: Alibaba PuHuiTi 2;
        font-size: 12px;
        font-style: normal;
        font-weight: 600;
        line-height: 20px; /* 83.333% */
        white-space: nowrap;
        &.normal {
          background: linear-gradient(270deg, #0dd3ff 0%, #009a94 100%);
        }
      }
      .target-num {
        transform: translateY(-2px);
        display: inline-flex;
        align-items: center;
        color: var(--unnamed, #fff);
        text-align: right;
        font-family: Alibaba PuHuiTi 2;
        font-size: 12px;
        font-style: normal;
        font-weight: 400;
        line-height: 20px; /* 83.333% */
        .num {
          font-weight: 600;
          &.red {
            color: #ff5656;
          }
        }
      }
      .progress-point {
        font-family: Alibaba PuHuiTi 2;
        font-size: 12px;
        font-style: normal;
        font-weight: 400;
        line-height: 14px; /* 116.667% */
        white-space: nowrap;
        .top {
          position: absolute;
          top: -22px;
          left: 0;
          transform: translateX(calc(-50% + 7px));
          color: var(--03, #ffbb53);
        }
        .arrow-top {
          position: absolute;
          top: -5px;
          left: 0;
          border-top: 5px solid #ffbb53;
          border-right: 6px solid transparent;
          border-bottom: 5px solid transparent;
          border-left: 6px solid transparent;
          border-radius: 4px;
          &.arrow-max {
            transform: translateX(-6px);
          }
        }
        .bottom {
          position: absolute;
          bottom: -20px;
          left: 0;
          transform: translateX(calc(-50% + 7px));
          color: #e17ef1;
        }
        .arrow-bottom {
          position: absolute;
          bottom: -5px;
          left: 0;
          border-top: 5px solid transparent;
          border-right: 6px solid transparent;
          border-bottom: 5px solid #e17ef1;
          border-left: 6px solid transparent;
          border-radius: 4px;
          &.arrow-max {
            transform: translateX(-6px);
          }
        }
        .max {
          left: auto !important;
          right: 0;
          transform: none;
        }
        .zero {
          transform: none;
        }
      }
    }
  }
  .right-top-tag {
    position: absolute;
    width: 84px;
    right: -16px;
    top: 6px;
    z-index: 9;
    transform: rotate(36.61deg);
    padding: 0px 12.286px 0px 22.696px;
    color: #ff5b27;
    background: rgba(255, 91, 39, 0.23);
    text-align: center;
    font-family: Alibaba PuHuiTi 2;
    font-size: 12px;
    font-style: normal;
    font-weight: 400;
    line-height: 22px; /* 183.333% */
    &.normal {
      color: #009a94;
      background: rgba(0, 154, 148, 0.23);
    }
  }
}
</style>
